<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.16"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Livox SDK API: sdk_core/include/third_party/spdlog/spdlog/details/circular_q.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(initResizable);
/* @license-end */</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="1.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Livox SDK API
   &#160;<span id="projectnumber">V2.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.16 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('circular__q_8h_source.html','');});
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">circular_q.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="circular__q_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">//</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment">// Copyright(c) 2018 Gabi Melman.</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">// Distributed under the MIT License (http://opensource.org/licenses/MIT)</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment">//</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160; </div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment">// cirucal q view of std::vector.</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="preprocessor">#pragma once</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160; </div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespacespdlog.html">spdlog</a> {</div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="keyword">namespace </span>details {</div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="keyword">template</span>&lt;<span class="keyword">typename</span> T&gt;</div>
<div class="line"><a name="l00014"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html">   14</a></span>&#160;<span class="keyword">class </span><a class="code" href="classspdlog_1_1details_1_1circular__q.html">circular_q</a></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;{</div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="keyword">public</span>:</div>
<div class="line"><a name="l00017"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#a50926d98e20ee48b70d4b66d99895e97">   17</a></span>&#160;    <span class="keyword">using</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#a50926d98e20ee48b70d4b66d99895e97">item_type</a> = T;</div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160; </div>
<div class="line"><a name="l00019"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#ab0aae072dd38824fee65ed9d48568c2f">   19</a></span>&#160;    <span class="keyword">explicit</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#ab0aae072dd38824fee65ed9d48568c2f">circular_q</a>(<span class="keywordtype">size_t</span> max_items)</div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;        : max_items_(max_items + 1) <span class="comment">// one item is reserved as marker for full q</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;        , v_(max_items_)</div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;    {</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;    }</div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160; </div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;    <span class="comment">// push back, overrun (oldest) item if no room left</span></div>
<div class="line"><a name="l00026"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#aaaab548bb6f5dd362458d6b044e0e950">   26</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#aaaab548bb6f5dd362458d6b044e0e950">push_back</a>(T &amp;&amp;item)</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    {</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;        v_[tail_] = std::move(item);</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;        tail_ = (tail_ + 1) % max_items_;</div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160; </div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;        <span class="keywordflow">if</span> (tail_ == head_) <span class="comment">// overrun last item if full</span></div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;        {</div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;            head_ = (head_ + 1) % max_items_;</div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;            ++overrun_counter_;</div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;        }</div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;    }</div>
<div class="line"><a name="l00037"></a><span class="lineno">   37</span>&#160; </div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;    <span class="comment">// Pop item from front.</span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;    <span class="comment">// If there are no elements in the container, the behavior is undefined.</span></div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#a6e05a29447127eadabf01175a6b3ddc0">   40</a></span>&#160;    <span class="keywordtype">void</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#a6e05a29447127eadabf01175a6b3ddc0">pop_front</a>(T &amp;popped_item)</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;    {</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;        popped_item = std::move(v_[head_]);</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        head_ = (head_ + 1) % max_items_;</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    }</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160; </div>
<div class="line"><a name="l00046"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#ae27eea7ecb58860f4471f473e02270f8">   46</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#ae27eea7ecb58860f4471f473e02270f8">empty</a>()</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    {</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;        <span class="keywordflow">return</span> tail_ == head_;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;    }</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#a6f9e90a9957c230376a463b20f909191">   51</a></span>&#160;    <span class="keywordtype">bool</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#a6f9e90a9957c230376a463b20f909191">full</a>()</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;    {</div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;        <span class="comment">// head is ahead of the tail by 1</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;        <span class="keywordflow">return</span> ((tail_ + 1) % max_items_) == head_;</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;    }</div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160; </div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="classspdlog_1_1details_1_1circular__q.html#a2f683dc45eca25efad9e415cf73c7ea0">   57</a></span>&#160;    <span class="keywordtype">size_t</span> <a class="code" href="classspdlog_1_1details_1_1circular__q.html#a2f683dc45eca25efad9e415cf73c7ea0">overrun_counter</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="keyword">    </span>{</div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;        <span class="keywordflow">return</span> overrun_counter_;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;    }</div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160; </div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="keyword">private</span>:</div>
<div class="line"><a name="l00063"></a><span class="lineno">   63</span>&#160;    <span class="keywordtype">size_t</span> max_items_;</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;    <span class="keyword">typename</span> std::vector&lt;T&gt;::size_type head_ = 0;</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;    <span class="keyword">typename</span> std::vector&lt;T&gt;::size_type tail_ = 0;</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160; </div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    std::vector&lt;T&gt; v_;</div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160; </div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    <span class="keywordtype">size_t</span> overrun_counter_ = 0;</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;};</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;} <span class="comment">// namespace details</span></div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;} <span class="comment">// namespace spdlog</span></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_ae27eea7ecb58860f4471f473e02270f8"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#ae27eea7ecb58860f4471f473e02270f8">spdlog::details::circular_q::empty</a></div><div class="ttdeci">bool empty()</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00046">circular_q.h:46</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_a6e05a29447127eadabf01175a6b3ddc0"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#a6e05a29447127eadabf01175a6b3ddc0">spdlog::details::circular_q::pop_front</a></div><div class="ttdeci">void pop_front(T &amp;popped_item)</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00040">circular_q.h:40</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_ab0aae072dd38824fee65ed9d48568c2f"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#ab0aae072dd38824fee65ed9d48568c2f">spdlog::details::circular_q::circular_q</a></div><div class="ttdeci">circular_q(size_t max_items)</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00019">circular_q.h:19</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_a50926d98e20ee48b70d4b66d99895e97"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#a50926d98e20ee48b70d4b66d99895e97">spdlog::details::circular_q&lt; item_type &gt;::item_type</a></div><div class="ttdeci">item_type item_type</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00017">circular_q.h:17</a></div></div>
<div class="ttc" id="anamespacespdlog_html"><div class="ttname"><a href="namespacespdlog.html">spdlog</a></div><div class="ttdef"><b>Definition:</b> <a href="async_8h_source.html#l00027">async.h:27</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_a2f683dc45eca25efad9e415cf73c7ea0"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#a2f683dc45eca25efad9e415cf73c7ea0">spdlog::details::circular_q::overrun_counter</a></div><div class="ttdeci">size_t overrun_counter() const</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00057">circular_q.h:57</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_a6f9e90a9957c230376a463b20f909191"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#a6f9e90a9957c230376a463b20f909191">spdlog::details::circular_q::full</a></div><div class="ttdeci">bool full()</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00051">circular_q.h:51</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html">spdlog::details::circular_q</a></div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00014">circular_q.h:14</a></div></div>
<div class="ttc" id="aclassspdlog_1_1details_1_1circular__q_html_aaaab548bb6f5dd362458d6b044e0e950"><div class="ttname"><a href="classspdlog_1_1details_1_1circular__q.html#aaaab548bb6f5dd362458d6b044e0e950">spdlog::details::circular_q::push_back</a></div><div class="ttdeci">void push_back(T &amp;&amp;item)</div><div class="ttdef"><b>Definition:</b> <a href="circular__q_8h_source.html#l00026">circular_q.h:26</a></div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_5f1136fe404e0a548faf586fae339a6a.html">sdk_core</a></li><li class="navelem"><a class="el" href="dir_fef6b6f1028f30fedf17225feaaa02fe.html">include</a></li><li class="navelem"><a class="el" href="dir_7bb3e31efd6b819bbb0704cee4a66d41.html">third_party</a></li><li class="navelem"><a class="el" href="dir_cf58c3a45797022668a1e269b5315a33.html">spdlog</a></li><li class="navelem"><a class="el" href="dir_248a80cf6760c7a1ab13394a1c16f7b2.html">spdlog</a></li><li class="navelem"><a class="el" href="dir_7d093cd833acfccb787639923feedd9d.html">details</a></li><li class="navelem"><a class="el" href="circular__q_8h.html">circular_q.h</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.16 </li>
  </ul>
</div>
</body>
</html>
